<?php
/**
 * Logger class definition
 *   
 * @author Sean Crystal <seancrystal@gmail.com>
 * @package MutantVole
 */

/**
 * Basic Logging class
 * @package MutantVole
 * @subpackage Base
 */
class Logger {
    
    public static function SetLogFile($filename) {
        Contract::Precondition(!empty($filename), '$filename cannot be empty');
        
        self::$logFile = $filename;
    }
    
    public static function SetDebug($debug = false) {
        self::$debug = $debug;
    }
    
    public static function Write($message) {
        if (!($fh = fopen(self::$logFile, 'a+'))) {
            throw new CannotOpenFileException(self::$logFile);            
        }
        
        $timeStamp = date('Y-m-d H:i:s');
        
        if (!(fwrite($fh, "{$timeStamp} {$message}\n"))) {
            throw new FailedToWriteToFileException(self::$logFile);
        }
        
        fclose($fh);
    }
    
    public static function DebugWrite($message) {
        if (self::$debug) {
            self::Write($message);
        }
    }
    
    protected static $logFile;
    protected static $debug;
}
?>